package com.dyh.quickdemozwei.mdh;


import java.io.ByteArrayInputStream;
import java.io.InputStream;

public interface SmartArgUtils {
     static <T> T softArgGet(int idx,Object[] args,Class<T> cls){
        return args.length-1>=idx? cls.cast(args[idx]) : null;
    }

    static <T> T softGet(Object o){
         return o==null?null:(T)o;
    }


    static <T> T softArgGet(int idx,Object[] args){
         if (args==null)
             return null;
         if (args.length-1>=idx){
             Object v =  args[idx];
             return v==null?null:(T)v;
         }
         return null;
    }


    static <T> T elect(T... candidates){
        if (candidates==null)
            return null;
        for (T candidate : candidates) {
            if (candidate!=null)
                return candidate;
        }
        return null;
    }

    public static void main(String[] args) {
//         String str = "adawd";
//        System.out.println(str.substring(1,str.length()-1));
            Object o1 = 1;
            Object o2 = Integer.valueOf(1);

            int i1 = softGet(o1);
            int i2 = softGet(o2);

            System.out.println();
        byte [] ba = new byte[]{1,2};
        InputStream is = new ByteArrayInputStream(ba);
    }
}
